'use strict';
/**
 *设置成为红娘
 * @returns
 */
const user = uniCloud.importObject('two-plus-one')
const db = uniCloud.database();
module.exports = async (obj) => {
	try{
		
		let user_order_success = true;
		let {
			data = {}
		} = obj;
		let {
			order_no,
			out_trade_no,
			total_fee,
			user_id,
			custom={}
		} = data; // uni-pay-orders 表内的数据均可获取到
		let id = user_id || custom.uid
		
		//异步更新奖励，会员身份等
		user.setIdentity({
			id: id,
			orderid: order_no,
		})
		let upRes = await db.collection("wolf-pay-order").where({
			order_no:order_no
		}).update({
			status:1
		})
		console.log("setProfit+++",upRes);
		if (!upRes.updated) {
			user_order_success = false //代表你自己的逻辑处理成功 返回 false 代表你自己的处理逻辑失败。
		}
		// console.log("type：test");
		return user_order_success;
		
		
	}catch(e){
		//TODO handle the exception
		console.log("setIdentity==================>>>>>>>>>",e);
	}
};